package cn.com.surker.material.controller;

import cn.com.surker.common.AbstractController;
import cn.com.surker.dto.main.MainMaterialSupplierRateDTO;
import cn.com.surker.dto.main.MainSupplierQueryDTO;
import cn.com.surker.material.service.MainMaterialSupplierRateService;
import cn.com.surker.material.service.MainSupplierService;
import cn.com.surker.spring.RestResultDto;
import cn.com.surker.system.model.CacheUser;
import cn.com.surker.vo.main.MainMaterialSupplierRateVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 材料抽检概率表
 */
@RestController
@RequestMapping("/main-material-supplier-rate")
public class MainMaterialSupplierRateController extends AbstractController {



    @Resource
    private MainMaterialSupplierRateService mainMaterialSupplierRateService;


    @Resource
    private MainSupplierService mainSupplierService;

    /**
     * 材料抽检概率表 分页方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/page")
    public RestResultDto pageData(@RequestBody MainMaterialSupplierRateDTO dto){
        IPage<MainMaterialSupplierRateVO> page = mainMaterialSupplierRateService.pageData(dto);
        return RestResultDto.success(page);
    }

    /**
     * 材料抽检概率表 更新方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/update")
    public RestResultDto update(@RequestBody MainMaterialSupplierRateDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(mainMaterialSupplierRateService.update(dto,user));
    }

    /**
     * 材料抽检概率表 更新方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/updatestatus")
    public RestResultDto updatestatus(@RequestBody MainMaterialSupplierRateDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(mainMaterialSupplierRateService.updatestatus(dto,user));
    }

    /**
     * 材料抽检概率表 新增方法
     * @param dto
     * @return
     */
    @PostMapping(value = "/save")
    public RestResultDto save(@RequestBody MainMaterialSupplierRateDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(mainMaterialSupplierRateService.saveRate(dto,user));
    }

    /**
     * 根据公司标识获取供应商数据
     * @param dto
     * @return
     */
    @PostMapping(value = "/getList")
    public RestResultDto listByOrgId(@RequestBody MainSupplierQueryDTO dto){
        return RestResultDto.success(mainSupplierService.listByOrgId(dto));
    }
}
